package com.itheima.homework.homework22;

import java.util.Collections;
import java.util.Comparator;
import java.util.TreeSet;

public class Demo22 {
    public static void main(String[] args) {
        TreeSet<Student> set=new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result =0;
                int score=o2.getScore()-o1.getScore();
                int age=o1.getAge()-o2.getAge();
                int name=o1.getName().compareTo(o2.getName());
                if(score!=0){
                    result=score;
                }else if(age!=0){
                    result=age;
                }else{
                    result=name;
                }
                return result;
            }
        }
        );


        Student stu1=new Student("Tom",20,90);
        Student stu2=new Student("Jerry",22,95);
        Student stu3=new Student("John",20,100);
        Student stu4=new Student("Lily",22,100);
        Student stu5=new Student("Lucy",22,90);
        Student stu6=new Student("Kevin",22,90);
        Collections.addAll(set,stu1,stu2,stu3,stu4,stu5,stu6);
        for (Student student : set) {
            System.out.println(student);
        }
    }
}
